package com.ellricky.baselib.ui.student;

import android.view.View;

import androidx.appcompat.widget.AppCompatEditText;

import com.andr.common.http.callback.JOCallback;
import com.andr.common.ui.activity.BaseToolBarActivity;
import com.andr.common.ui.mvp.BasePresenter;
import com.andr.common.util.EmptyUtil;
import com.andr.common.util.ToastUtil;
import com.ellricky.baselib.BaseConstant;
import com.ellricky.baselib.R;
import com.ellricky.baselib.http.HttpUtils;
import com.ellricky.baselib.util.EAppUtil;
import com.flyco.roundview.RoundTextView;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import static com.ellricky.baselib.http.Api.API_STU_APPLY_SUBMIT;

/**
 * 审批意见
 */
public class StudentApplyAdviceActivity extends BaseToolBarActivity<Void, BasePresenter<Void>> {

    private AppCompatEditText etContent;
    private RoundTextView btnSubmit;

    private String applyId, applyType;


    @Override
    public int getContentLayout() {
        return R.layout.base_activity_stu_apply_audit_advice;
    }

    @Override
    public void initUIView() {
        super.initUIView();
        mTvTitle.setText(R.string.base_apply_audit_advice);

        etContent = findViewById(R.id.etContent);
        btnSubmit = findViewById(R.id.btnSubmit);

        btnSubmit.setOnClickListener(this);

        applyId = getIntent().getStringExtra(BaseConstant.KEY_ID);
        applyType = getIntent().getStringExtra(BaseConstant.KEY_APPLY_TYPE);


    }

    @Override
    public void onClickView(View v) {
        super.onClickView(v);
        if (v == btnSubmit) {
            postUpload();
        }
    }

    private void postUpload() {

        String content = Objects.requireNonNull(etContent.getText()).toString().trim();
        if (EmptyUtil.isEmpty(content)) {
            ToastUtil.show(this, "请填写审批意见");
            return;
        }

        String url = EAppUtil.getApiHost() + API_STU_APPLY_SUBMIT;
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("id", applyId);
        paramMap.put("applyType", applyType);
        paramMap.put("appointDes", content);
        HttpUtils.getInstance().post(url, paramMap, new JOCallback(this) {
            @Override
            public void onSuccess(JSONObject dataJO, String msg) {
                setResult(BaseConstant.RESULT_CODE_ADD);
                finish();
            }
        });

    }


}